package com.hamll.search.listener;

import com.hamll.search.service.SearchService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


@Component
public class HamllListener {
    @Autowired
    private SearchService searchService;

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("mall.insert.queue"),
            exchange = @Exchange(name = "mall.topic",type = ExchangeTypes.TOPIC),
            key = "mall.insert"
    ))
    public void listenInsert(Long id){
        if (id!=null){
            searchService.insert(id);
        }
    }

    @RabbitListener(bindings = @QueueBinding(
            value = @Queue("mall.delete.queue"),
            exchange = @Exchange(name = "mall.topic",type = ExchangeTypes.TOPIC),
            key = "mall.delete"
    ))
    public void listenDelete(Long id){
        if (id!=null){
            searchService.delete(id);
        }
    }
}
